package com.shycloud.mido.organ.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.organ.api.entity.MemberEntity;
import com.shycloud.mido.organ.api.enums.RankingTypeEnum;
import com.shycloud.mido.organ.mapper.MemberMapper;
import com.shycloud.mido.organ.ranking.Ranking;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@AllArgsConstructor
@RequestMapping("/wxMini")
public class WxMiniController {

	private final Map<String, Ranking> rankingTypeMap;

	private MemberMapper memberMapper;


	/**
	 * 后台 - 社区用户管理 获取排名类型
	 *
	 * @return {@link R}
	 * @author nianhua.jiang
	 * @date 2021/2/26 10:22
	 **/
	@GetMapping("/getRankingTypes")
	public R getRankingTypes() {
		return new R(RankingTypeEnum.getAllTypes());
	}

	/**
	 * 后台 - 社区用户管理 获取排名列表
	 *
	 * @return {@link R}
	 * @author nianhua.jiang
	 * @date 2021/2/26 10:22
	 **/
	@GetMapping("/getRankingList")
	public R getRankingList(String type, String username, Integer current, Integer size) {

		Page page = new Page(current, size);

		return new R(rankingTypeMap.get(type).getRankingList(username, page));
	}

	@GetMapping("/disable")
	public R disable(String username, String miniStatus) {
		MemberEntity memberEntity = memberMapper.selectOne(new QueryWrapper<MemberEntity>().eq("username", username));

		memberEntity.setMiniStatus(miniStatus);

		return new R(memberMapper.updateById(memberEntity));
	}

}
